<template>
    <div class="box">
    <van-nav-bar title="京东注册" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit">
        <van-cell-group inset>
            <van-field v-model="loginname" name="用户名" label="用户名" placeholder="用户名"
                :rules="[{ required: true, message: '请输入正确格式', pattern: phone }]" />
            <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码"
                :rules="[{ required: true, message: '密码格式不正确', pattern: pass }]" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                提交
            </van-button>
        </div>
    </van-form>
    <van-cell-group title="去注册">
        <van-cell title="快速注册" is-link arrow-direction="right" @click="zc" />
    </van-cell-group>
    <tabber></tabber>
</div>
</template>

<script setup lang="ts">
import tabber from "@/components/tabber.vue"
import { ref } from "vue"
import { useRouter } from "vue-router";
import { useCounterStore } from "@/stores/counter"
import { storeToRefs } from "pinia"
import { enter } from "@/service/login"
let router = useRouter()
let store = useCounterStore()
const onClickLeft = () => {
    router.push("/home")
}
let phone = ref(/^1[3-9]\d{9}$/)
let pass = ref(/(?=.*[a-z])(?=.*[A-Z])(?=.*[1-9])(?=.*[\W]).{4,}/)
let loginname = ref<any>("")
let password = ref<any>("")
const onSubmit = () => {
    loginname.value = sessionStorage.getItem("tel")
    password.value = sessionStorage.getItem("password")
    enter(loginname.value, password.value).then((res: any) => {
        if (res.code === "200") {
            router.push("/home")
            store.userInfo = res.data
        }
    })
}
const zc = () => {
    router.push("/regist/step1")
}

</script>

<style scoped>
.box{
    padding-bottom: 60px;
}
</style>